/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @file TestSoftServo.c
* 
* Library for testing the softengine library code.
* 
* @author Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdlib.h>
#include <softservo.cpp>
#include <timer.cpp>

/**
* @example TestSoftServo.c
*/

int main(int argc, char *argv[])
{
	if(argc<2)
	{
		puts("\nUSE:\nTestSoftEngine <acceleration> <min_value> <max_value> <useconds timer>\n");
		puts("\t  e.g.");
		puts("\t    TestSoftEngine 6 -100 100 100000 => Accelerate 6 each 0,1 second from -100 to 100.\n");

		exit(EXIT_SUCCESS);
	}
	
	CMTimer temp(atol(argv[4]));
	CMSoftServo engine(atol(argv[1]),atol(argv[2]),atol(argv[3]));

	// Go up
	engine.setEnd(32767);
	while(engine.getNow() < atoi(argv[3]))
	{
		if(temp.check()==1)
		{
			engine.update();
			printf("Value:\t%d\n",engine.getNow());
		}
	}
	
	// Go down
	engine.setEnd(-32768);
	while(engine.getNow() > atoi(argv[2]))
	{
		if(temp.check()==1)
		{
			engine.update();
			printf("Value:\t%d\n",engine.getNow());
		}
	}

}
